using Microsoft.Win32;
using System;
using System.Windows;

namespace FinanceSectionUtilities20250129
{
    public partial class TestDemoWindow1 : Window
    {
        BudgetWindowViewModel budgetWindowViewModel = new BudgetWindowViewModel();
        public TestDemoWindow1()
        {
            InitializeComponent();
            InitializeComboBoxes();
            this.DataContext = budgetWindowViewModel;
        }

        private void InitializeComboBoxes()
        {
            // 初始化年份（2024-2035）
            for (int year = 2024; year <= 2035; year++)
            {
                cmbYear.Items.Add(year);
            }
            cmbYear.SelectedIndex = 0;
        }

        private void BrowseExport_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog();
            if (dialog.ShowDialog() == true)
            {
                txtExportPath.Text = dialog.FileName;
                UpdateResult($"已选择导出文件：{dialog.FileName}");
            }
        }

        private void BrowseDept_Click(object sender, RoutedEventArgs e)
        {
            OpenFolderDialog openFolderDialog = new()
            {
                Multiselect = false,
                Title = "选择一个文件夹"
            };
            bool? target = openFolderDialog.ShowDialog();
            if (target == true) { 
                txtDeptPath.Text = openFolderDialog.FolderName;
            }
        }

        private void BrowseSummary_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog();
            if (dialog.ShowDialog() == true)
            {
                txtSummaryPath.Text = dialog.FileName;
                UpdateResult($"已设置汇总文件：{dialog.FileName}");
            }
        }

        private void UpdateResult(string message)
        {
            txtResult.Text += $"{DateTime.Now:HH:mm:ss} - {message}{Environment.NewLine}";
            txtResult.ScrollToEnd();
        }

        private void Reset_Click(object sender, RoutedEventArgs e)
        {
            txtExportPath.Clear();
            txtDeptPath.Clear();
            txtSummaryPath.Clear();
            cmbDepartment.SelectedIndex = -1;
            cmbYear.SelectedIndex = 0;
            cmbMonth.SelectedIndex = 0;
            txtResult.Clear();
        }

        private void Run_Click(object sender, RoutedEventArgs e)
        {
            // 示例运行逻辑
            UpdateResult("开始处理数据...");
            // 添加实际业务逻辑
            UpdateResult("处理完成！");
        }

        private void Exit_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}